package com.easy;

/**
 * Created by Lxk on 2019/5/16.
 */
public class Solution169 {

    public int majorityElement(int[] nums) {
        int count = 1;
        int base = nums[0];
        for(int i = 1;i < nums.length; i++){
            if(base == nums[i]){
                count++;
            }else{
                count--;
                if(count==0){
                    base = nums[i+1];
                }
            }
        }
        return base;
    }

}
